Repository navigation
Optionally keep only inventory variables provided by inventory sources - #1202
Open
fernandorocagonzalez wants to merge 1 commit into
Open
fernandorocagonzalez wants to merge 1 commit into
fernandorocagonzalez wants to merge 1 commit into
Conversation
…sources Overwrite variables only removes the inventory variables a source wrote on its previous sync. Variables written before that tracking existed, added or edited by hand, or written by a source that was later deleted stay in the inventory forever, so a variable renamed in group_vars/all keeps its old value and roles keep reading it. The new variables_from_sources_only flag on regular inventories makes every sync remove the inventory variables that no source of the inventory provides. Since a source that has not synced since the tracking was added has no record of its variables, nothing is removed until every source has recorded them, tracked by the new managed_inventory_variables_recorded field on the inventory source. Signed-off-by: fernandorocagonzalez <fernandorocagonzalez@gmail.com>
fernandorocagonzalez
force-pushed
the
feat-inv-prune-unmanaged-vars
branch
from
November 13, 2026 19:08
0b2497b to
a4c3816
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY
Since #1055, a sync with Overwrite variables removes the inventory variables that the same source wrote on its previous sync and no longer provides. That cleanup is careful on purpose, so some variables never go away:
We hit the first case right after upgrading. A key renamed in
group_vars/allkept its old value in the inventory, and the role kept preferring the old key, so the new one was ignored. Keys removed from the repo months ago are still sitting in the inventory variables, and the only way to clean them up is by hand, in every inventory that uses that source.This adds an opt-in flag on the inventory,
variables_from_sources_only. When it is set, every sync removes the inventory variables that no source of the inventory provides.How it works:
Inventory.variables_from_sources_only, defaultfalse, so nothing changes for existing inventories. It's only accepted on regular inventories (it's rejected on smart ones and not exposed on the constructed and federated endpoints). It's copied along with the inventory._update_inventory, when the flag is set, the sync keeps a variable only if the current source provides it or another source of the inventory recorded it on its own last sync (managed_inventory_variablesfrom Remove stale inventory variables on sync when "Overwrite variables" is enabled #1055). Everything else is removed and logged at info level, so it shows up in the sync output. This doesn't depend onoverwrite_vars.InventorySource.managed_inventory_variables_recordedflag, set by every successful sync. While any other source of the inventory still has it unset, the sync removes nothing and logs a warning naming the sources that still need to sync. That way a sync of one source can't wipe the variables of a source that has never recorded them.perform_updateadvisory lock and transaction that Remove stale inventory variables on sync when "Overwrite variables" is enabled #1055 already uses, so syncs of different sources don't race, and a failed sync rolls back both the variables and the record.0234.UI: a Variables From Sources Only checkbox under Options in the inventory form, listed under Enabled Options in the details, with help text. Spanish translation added, and the other locales re-extracted.
Docs:
docs/inventory/variables_from_sources_only.md, plus a mention in the inventories user guide.ISSUE TYPE
COMPONENT NAME
ASCENDER VERSION
ADDITIONAL INFORMATION
Tests added:
TestInventoryVariablesFromSourcesOnlyintest_inventory_import.py. It covers: untracked and hand-added variables removed; kept when the flag is off; edited variables removed once no source provides them; works withoutoverwrite_vars; variables of other sources kept; nothing removed until every source has synced; a source with no variables counts as synced; the variables of a deleted source removed on the next sync; a failed sync changes nothing.Checks from
.github/copilot-instructions.md, run inside the dev container:End to end on the docker-compose dev environment, with a git project whose
inventory.yamlandgroup_vars/all/feed an SCM source with overwrite variables on:old_keyfrom the repo and renamingrenamed_fromtorenamed_tobehaves as in Remove stale inventory variables on sync when "Overwrite variables" is enabled #1055. A key added by hand and a stand-in for a pre-upgrade leftover both stay.